package com.whcoding.encrypt.controller;

import com.whcoding.encrypt.annotation.Decrypt;
import com.whcoding.encrypt.annotation.Encrypt;
import com.whcoding.encrypt.entity.OrmDeptVO;
import com.whcoding.encrypt.entity.RespBeanVO;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @program: spring-boot-learning
 * @description:
 * @author: whcoding
 * @create: 2022-06-16 11:31
 **/
@RestController
@RequestMapping("encrypt")
public class EncryptController {

	/**
	 * 对返回结果不执行加密操作
	 *
	 * @return
	 */
	@GetMapping("/queryDept")
	public RespBeanVO queryDept() {
		return RespBeanVO.ok("ok", getDefaultDeptVO());
	}


	/**
	 * 对返回结果进行加密
	 *
	 * @return
	 */
	@GetMapping("/getDept")
	@Encrypt
	public RespBeanVO getDept() {
		return RespBeanVO.ok("ok", getDefaultDeptVO());
	}

	/**
	 * 对传递的参数进行解密
	 *
	 * @param deptVO
	 * @return
	 */
	@PostMapping("/addDept")
	public RespBeanVO addDept(@RequestBody @Decrypt OrmDeptVO deptVO) {
		System.out.println("deptVO = " + deptVO);
		return RespBeanVO.ok("ok", deptVO);
	}

	/**
	 * 获取默认的deptVO
	 *
	 * @return
	 */
	private OrmDeptVO getDefaultDeptVO() {
		OrmDeptVO deptVO = new OrmDeptVO();
		deptVO.setId((long) 99);
		deptVO.setDeptNo("KF_01");
		deptVO.setDeptName("开发部");
		deptVO.setDeptTyep(01);
		deptVO.setCreateTime(new Date());
		deptVO.setCreateUserId(1);
		return deptVO;
	}
}
